using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using ilibrary.source.model;


namespace ilibrary.source.views
{
    public partial class ScanProgressForm : BaseForm, ScanHandler
    {
        bool stopScanning = false;

        public ScanProgressForm()
        {
            InitializeComponent();
        }

   

        private void btnCancel_Click(object sender, EventArgs e)
        {
            stopScanning = true;
        }

        delegate bool SetTextCallback(float percent,string text);

        public bool ebookAdded(float percent, string filename)
        {
            if (this.txtMessage.InvokeRequired && this.progressBar.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(ebookAdded);
                this.Invoke(d, new object[] { percent,filename });
            }
            else
            {
                txtMessage.Text = filename;
                progressBar.Value = (int)percent;
                this.Refresh();
            }

            
            return !stopScanning;
        }

        
        private void ScanProgressForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            stopScanning = true;
        }

        public void reset()
        {
            this.progressBar.Value = 0;
            stopScanning = false;
        }

   

    }
}